package com.powersystem.demo.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powersystem.demo.entity.PsUser;
import com.powersystem.demo.service.IPsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author linrongji
 * @since 2019-11-14
 */
@RestController
public class PsUserController {
    @Autowired
    private IPsUserService ipsUserService;
    @RequestMapping("userRole")
    // 根据用户的openId查询用户权限
    public int userRole(PsUser psUser){
        return ipsUserService.fetchUserRole(psUser.getOpenId());
    }

    @RequestMapping("userInfo")
    //根据roleId 查询
    public List<PsUser> userInfo(int roleId){
        return ipsUserService.selectByRoleId(roleId);
    }
    @RequestMapping("selectAllUserInfo")
    //查询所有的用户、
    public List<PsUser> selectAllUserInfo(){
        IPage<PsUser> page = new Page<PsUser>(0,4);
        QueryWrapper<PsUser> wrapper = new QueryWrapper<>();
        return ipsUserService.page(page,wrapper).getRecords();
    }
    @RequestMapping("fetchByUserNameAndStauts")
    public List<PsUser> fetchByUserNameAndStatus(String userName,int status){
        IPage<PsUser> page = new Page<>(0,4);
        QueryWrapper<PsUser> warpper = new QueryWrapper<>();
        return ipsUserService.selectByuserNameAndUserStatus(userName,status);
    }
    @RequestMapping("addUserInfo")
    public boolean addUserInfo(PsUser psUser){
        return ipsUserService.save(psUser);
    }
    @RequestMapping("updateUserInfo")
    public boolean updateUserInfo(PsUser psUser){
        return ipsUserService.updateById(psUser);
    }
    @RequestMapping("removeUserInfo")
    public boolean removeUserInfo(PsUser psUser){
        return ipsUserService.removeById(psUser.getId());
    }


}

